<uieip type="page" value="base"></uieip>
<uieip type="reg" value="console,cms,login"></uieip>
<div id="header">
    <div class="navbar navbar-default navbar-fixed-top" role="navigation">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span><span
                        class="icon-bar"></span><span class="icon-bar"></span>
                </button>
                <a href="http://www.yqsite.com/" class="navbar-brand" style="padding:0 0 0 15px;" title="远齐科技(北京)有限公司"
                    target="_blank">
                    <img src="/images/uieiplogo3.png" style="max-height:50px;" /></a>
            </div>
            <div class="navbar-collapse collapse">
                <uieip id="nav" type="tmpl" value="cms.nav" js="bootstrap">
                </uieip>
            </div>
        </div>
    </div>
</div>
<script runat="server">
    function bootstrap(res) {
        var h = bootstrap_html(res.navs, res.path, true);

        var user_row = login.userinfo();
        h += '<ul class="nav navbar-nav pull-right">';
        if (user_row === undefined) {
            h += '    <li>';
            h += '        <a href="javascript:void(0)" onclick="userlogin();return false;" title="用户登录" target="_Blank">登录</a>';
            h += '    </li>';
        } else {
            h += '    <li class="dropdown">';
            h += '        <a href="javascript:void(0)" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true"><b class="glyphicon glyphicon-user"></b> ' + user_row["name"] + '<b class="caret"></b></a>';
            h += '        <ul class="dropdown-menu">';
            h += '            <li><a href="/account/index.html" target="_blank" title="会员中心">会员中心</a></li>';
            h += '            <li><a href="javascript:void(0)" onclick="userlogout();return false;" title="退出登录"><span class="glyphicon glyphicon-log-out"></span> 退出</a></li>';
            h += '        </ul>';
            h += '    </li>';
        }
        h += '</ul>';
        return h;
    }

    function bootstrap_html(navs, path, root) {
        if (navs.length == 0) {
            return "";
        }

        var h = '';
        if (root) {
            h += '<ul class="nav navbar-nav">';
            h += '   <li class="nav-item' + (path == "" ? " active" : "") + '">';
            h += '      <a class="nav-link' + (path == "" ? " active" : "") + '" href="' + (path == "" ? "javascript:void(0);" : "/") + '">首页</a>';
            h += '   </li>';
        } else {
            h += '<ul class="dropdown-menu">';
        }

        for (var i = 0; i < navs.length; i++) {
            var nav = navs[i];

            if (!nav.IsDel) {
                var s_h = bootstrap_html(((nav.Subs === undefined || nav.Subs === null) ? [] : nav.Subs), path, false);
                var href = "";
                if (nav.LinkUrl != "") {
                    if (!(nav.LinkUrl.substring(0, 7) == "http://" || nav.LinkUrl.substring(0, 8) == "https://")) {
                        if (nav.LinkUrl == path) {
                            href = "javascript:void(0);";
                        } else {
                            href = "/" + nav.LinkUrl + "/";
                        }
                    } else {
                        href = nav.LinkUrl;
                    }
                } else {
                    if (nav.Path == path) {
                        href = "javascript:void(0);";
                    } else {
                        href = "/" + nav.Path + "/";
                    }
                }

                if (s_h == "") {
                    var active = (path == nav.Path) ? true : false;
                    h += '   <li class="nav-item' + (active ? " active" : "") + '">';
                    h += '       <a class="nav-link' + (active ? " active" : "") + '" href="' + href + '"' + (nav.Blank ? ' target="_blank"' : '') + '">' + nav.Name + '</a>';
                    h += '   </li>';
                } else {
                    var active = s_h.indexOf(" active") > 0 ? true : false;
                    h += '   <li class="nav-item dropdown' + (active ? " active" : "") + '">';
                    h += '      <a class="nav-link dropdown-toggle' + (active ? " active" : "") + '" data-bs-toggle="dropdown" href="' + href + '"' + (nav.Blank ? ' target="_blank"' : '') + ' role="button" aria-expanded="false">' + nav.Name + '<b class="caret"></b></a>';
                    h += s_h;
                    h += '   </li>';
                }
            }
        }
        h += "</ul>"

        return h
    }
</script>